//app.js
var payService = require("./service/pay/index");
var cacheService = require("./common/cache");

App({
  onLaunch: function () {
      console.log("app第一个进入的页面")

      // 初始化调用获取openid
      this.getOpenId(this);
  },

  getOpenId(that){
		wx.login({
			success(res) {
				var code = res.code;
				if (code) {
					// 2：通过调用接口通过code获取openid
					payService.getOpenid(code).then(res=>{
            var openId = res.openid;  
            //that.globalData.openId = openId;
            //wx.setStorageSync('openId',openId);
            cacheService.setCache("openId",openId);
					})
				}
			}
		});
	},
	

  globalData: {
    openId:"",
    userId:""
  }
})